package edu.mtu.citizenscience.cs.notepad;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.androidquery.AQuery;

import edu.mtu.citizenscience.cs.notepad.activity.HelpActivity;
import edu.mtu.citizenscience.cs.notepad.activity.R;
import edu.mtu.citizenscience.cs.notepad.activity.UploadActivity;
import edu.mtu.citizenscience.cs.notepad.activity.noteslist.NoteActivity;

/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * Base class for NPListActivity
 * imports android-query and adds menu
 */
public class NPListActivity extends ListActivity {
	public AQuery aq;

	/**
	 * UEListActivity creation handler
	 *
	 * @param   Bundle - Bundle with launch info
	 * @return  void
	 */
	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
        		
		this.aq = new AQuery(this); // the android-query library object
        		
		// Make sure we're running on Honeycomb or higher to use ActionBar APIs
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) 
		{
			// For the main activity, make sure the app icon in the action bar
			// does not behave as a button
			this.getActionBar().setHomeButtonEnabled(false);
		}
	}

	/**
	 * Create the android menu
	 *
	 * @param   menu - Menu - The options menu in which you place your items.
	 * @return  boolean - true as we want the menu to be displayed
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		this.getMenuInflater().inflate(R.menu.main_menu, menu);
		
		return true;
	}
	
	/**
	 * Handle menu item selected
	 *
	 * @param   item - MenuItem - The menu item that was selected.
	 * @return  boolean - boolean Return false to allow normal menu processing to proceed, true to consume it here.
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) 
	{
		 // Switch over menu options
		 switch (item.getItemId()) 
		 {
		 	case R.id.menu_new:
		 		// Launch Note Activity to create a new note
		 		this.startActivity(new Intent(this, NoteActivity.class));
		 		return true;
		 	case R.id.menu_help:
		 		// Launch Help Activity to display help info
		 		this.startActivity(new Intent(this, HelpActivity.class));
		 		return true;
		 	case R.id.menu_upload:
		 		// Launch Upload Activity to upload notes
		 		this.startActivity(new Intent(this, UploadActivity.class));
		 		return true;
		 	default:
		 		return super.onOptionsItemSelected(item);
		 }
	}

}